package com.chencs.common.grant.service;


import com.chencs.common.grant.mapper.RoleMapper;
import com.chencs.vo.common.grant.RoleModel;
import framework.model.ResponseOptUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by chencs on 2017/5/29.
 */
@Service
@Transactional
public class RoleService {

    @Autowired
    private RoleMapper roleMapper;


    public String  add(RoleModel model) {

       try {
           RoleModel roleModel  = roleMapper.select(model.getRoleCode());
           if(roleModel!=null){ //已经存在
               return ResponseOptUtil.commonMsgError("角色代码已经存在");
           }else{
               roleMapper.add(model);
               return ResponseOptUtil.commonSucess();
           }
       }catch (Exception e){
           return ResponseOptUtil.commonMsgError("添加角色异常");
       }

    }


    public RoleModel findRoleById(String roleId){
        return roleMapper.selectByRoleID(roleId);
    }

    public void delete(RoleModel model) {
        roleMapper.delete(model.getRoleCode());
    }

    public void update(RoleModel model) {
        roleMapper.update(model);
    }

    public List<RoleModel> getList() {
        return  roleMapper.list();
    }


}
